package java.util.concurrent;

public class SampleCountDownLatchBlockingMainThread {
	public static void main(String[] args) throws InterruptedException {
		int count = 100;

		// 结束的倒数锁
		final CountDownLatch end = new CountDownLatch(count);

		final ExecutorService exec = Executors.newFixedThreadPool(10);
		for (int index = 0; index < count; index++) {
			final int NO = index + 1;
			Runnable run = new Runnable() {
				public void run() {
					try {

						System.out.println(Thread.currentThread().getName() + " No." + NO + " begin");
						Thread.sleep((long) (Math.random() * 10000));
						System.out.println(Thread.currentThread().getName() + " No." + NO + " end");
					} catch (InterruptedException e) {
					} finally {
						end.countDown();
					}
				}
			};
			exec.submit(run);
		}

		end.await();
		exec.shutdown();
		System.out.println("Game Over");
	}
}
